<template>
	<view>
		<u-navbar :title="navTitle" :autoBack="true" :placeholder="true">
		</u-navbar>
		<view v-if="data" class="container">
			<view class="data-info">
				<img :src="data.avatarUrl" alt="" class="avatarUrl" />
				<view class="name">{{data.name}}</view>
				<view class="welcomeMsg">{{data.welcomeMsg}}</view>
			</view>
			<view class="actions">
				<view class="actions-item" @click="handleClick">
					<view><img src="../../static/images/ico_04.png" alt="" srcset="" /></view>
					<view>清除聊天记录</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: null,
				navTitle: "",
				datasetId:""
			}
		},
		onLoad(options) {
			this.datasetId = options.datasetId
			const AiList = uni.getStorageSync("AiList")
			AiList.forEach(item => {
				if (item.id == options.datasetId) {
					this.data = item
				}
			})
			this.navTitle = this.data.name
			uni.setNavigationBarTitle({
				title: this.data.name
			})
		},
		methods: {
			handleClick() {
				let messageList = uni.getStorageSync("messages")?uni.getStorageSync("messages"):[]
				let newMessageList = messageList.filter((item)=>item.datasetId !=this.datasetId)
				console.log(newMessageList)
				uni.removeStorageSync("messages")
				uni.setStorageSync("messages", newMessageList)
				uni.showToast({
					icon: 'none',
					title: "清除成功"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding: 10px;
	}

	.data-info {

		margin-top: 40px;
		display: flex;
		flex-direction: column;
		align-items: center;

		.name {
			margin-top: 10px;
		}

		.avatarUrl {
			width: 100px;
			height: 100px;
			border-radius: 100px;
		}

		.welcomeMsg {
			margin-top: 20px;
			color: #999999;
			font-size: 14px;
		}
	}

	.actions {
		margin-top: 20px;

		.actions-item {
			display: flex;
			align-items: center;
			background: #f2f2f2;
			padding: 10px 20px;
			border-radius: 5px;
		}

		img {
			width: 25px;
			height: 25px;
			margin-right: 10px;
		}
	}
</style>